package nmap;

import freemap.Freemap;
import freemap.Node;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author chris
 */
public class nmapToFreemap {

    public static void main(String[] args) {
        nmapToFreemap go = new nmapToFreemap();
        go.run(args);
    }

    private void run(String[] args) {
        try {
            File f = new File("C:\\Users\\chris\\Dropbox\\nmap-scan2.xml");
            Freemap fm = new Freemap().xmlToFreemapTransformation(f);
            addChanges(fm.getRootNode());
            fm = fm.alternateNodes(fm);
            BufferedWriter out = new BufferedWriter(new FileWriter("C:\\Users\\chris\\Dropbox\\nmap-scan2.mm"));
            out.write(fm.createMap());
            out.close();
        } catch (IOException ex) {
            Logger.getLogger(nmapToFreemap.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    /*
     * Add Nmap scan changes
     */
    private void addChanges(Node node) {
        for (Node n : node.getChildren()) {
            if (n.getText().equals("ports") || n.getText().equals("status")
                    || n.getText().equals("times") || n.getText().equals("scaninfo")
                    || n.getText().equals("runstats")
                    || n.getText().equals("times")) {
                n.setFolded(Boolean.TRUE);
                if (n.getChildren().size() > 0) {
                    addChanges(n);
                }
                System.out.println("Folded");
            }
        }
    }
}
